﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class exame2_rayChk : MonoBehaviour
{
    public Transform rayStart;
    public Transform rayEnd;
    Vector3 direction;
    float timer = 0f;
    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        direction = (rayEnd.position - rayStart.position) * 300;
        Ray ray = new Ray(rayStart.position,direction);
        RaycastHit info;
        if(Physics.Raycast(ray,out info))
        {
            if(info.collider.tag.Equals("Enemy"))
            {
                timer += Time.deltaTime;
                if (timer > 1)
                {
                    info.collider.SendMessageUpwards("TakeDamage",5,SendMessageOptions.DontRequireReceiver);
                    timer = 0;
                }
            }
        }
    }
}
